import TableList from "@components/templates/customtablelist";
import { HttpAccountBillList, HttpDelAccountBill } from "@/service/accountbill";
import { HttpCarrierServiceList} from '@/service/api/views'
import { FSAPI } from '@/utils/assist';
import { mapGetters } from 'vuex'
export default {
    mixins: [TableList],
    data() {
        return {
            isMixin: true,
            title: "打单列表",
            Searchs: {
                show: true,
                labelWidth: 90
            },
            Tools: { show: true },
            Plugins: { show: true },
            carrierServiceList:[],
        };
    },
    created(){
        HttpCarrierServiceList().then(res=>{
            this.carrierServiceList = res.data.map(item=>{
                return {
                    value:item.carrierServiceCode,
                    label:item.carrierServiceCode+' ('+item.carrierServiceName+')',
                }
            })
        })
    },
    methods: {
        ajaxRequest: HttpAccountBillList,
        interceptRequest (params) {
            if (params.search.BT_createdAt&&params.search.BT_createdAt[0]!='') {
                params.search.BT_createdAt = this.handleDateFormat(params.search.BT_createdAt[0],'yyyy-mm-dd') + ' ~ ' + this.handleDateFormat(params.search.BT_createdAt[1],'yyyy-mm-dd')
            }
            return params
        },
        handleOperates(params = "", type, batch) {
            switch (type) {
                case "add":
                    this.$router.push({
                        name: "accountbillUpdate",
                        params: { type: "add" },
                    });
                    break;
                case "query":
                    this.$router.push({
                        name: "accountbillUpdate",
                        params: { type: "query" },
                        query: { id: params }
                    });
                    break;
                case "edit":
                    this.$router.push({
                        name: "accountbillUpdate",
                        params: { type: "edit" },
                        query: { id: params }
                    });
                    break;
                case "del":
                    this.operate = {
                        show: true,
                        alert: "error",
                        params: { id: params },
                        title: "删除",
                        ajaxRequest: HttpDelAccountBill
                    };
                    break;
                case 'exportExcel':
                    this.handleWebfs(
                        process.env.VUE_APP_APIURL_SHIP + "/api/jwt/spl/thirdPartyAccount/export",{...this.formData,rows:1000},
                        "download"
                    );
                    // FSAPI.download(global.APIURL_HOST + '/api/jwt/spl/thirdPartyAccount/export', {...this.formData,rows:1000})
                    break;
            }
        },
        getOperateNodeMap(row) {
            const { id } = row;
            return [
                {
                    label: "编辑",
                    show: true,
                    params: id,
                    operate: "edit"
                },
                {
                    label: "删除",
                    show: true,
                    params: id,
                    operate: "del"
                }
            ];
        }
    },
    computed: {
        ...mapGetters('dictionary', ['getSysAllList']),
        ToolsData() {
            return [
                {
                    name: "添加",
                    operate: "add",
                    theme: "primary"
                },
                {
                    name: "导出",
                    operate: "exportExcel",
                    theme: "success"
                },
            ];
        },
        SearchsData() {
            return [
                {
                    label: "customer",
                    tag: "Select",
                    key: "EQ_organizationId",
                    props: {
                        filterable: true
                    },
                    show: true,
                    options: this.getSysAllList
                },
                {
                    label: 'shipper Code',
                    tag: "Input",
                    key: "CN_shipperCode",
                    show: true
                },
                {
                    label: "accountNumber",
                    tag: "Input",
                    key: "CN_accountNumber",
                    show: true
                },
                 {
                    label: "BillAcount",
                    tag: "Input",
                    key: "CN_thirdPartyAccount",
                },
                {
                    label: "serviceCode",
                    tag: "Select",
                    key: "EQ_serviceCode",
                    options: this.carrierServiceList
                },
                {
                    label: "carrier",
                    tag: "Select",
                    key: "CN_carrier",
                    options:[{
                        label: "FedEx",
                        value: "FedEx"
                    }, {
                        label: "UPS",
                        value: "UPS"
                    }, 
                    {
                        label: "UPS1",
                        value: "UPS1"
                    },{
                        label: "UPSCA",
                        value: "UPSCA"
                    },{
                        label: "Ontrac",
                        value: "ontrac"
                    }
                    ],
                    props: {
                        filterable: true
                    },
                },
                {
                    label: "Creation time",
                    tag: "DatePicker",
                    key: "BT_createdAt",
                    // hideSearchTip:true,
                    props: {
                        options:this.options,
                        type: 'daterange',
                        confirm: false,
                    },
                    style: 'width:200px'
                }
            ];
        },
        columns() {
            return [
                {
                    title: "操作",
                    width: 90,
                    render: this.getOperateNodes
                },
                {
                    title: "carrier",
                    key: "carrier"
                },
                {
                    title: "customer",
                    key: "organizationId",
                    render: (h, { row }) => {
                        return (this.getSysAllList.find(item => item.value == row.organizationId) || {}).label || ""
                    },
                },
                {
                    title: "shipper Code",
                    key: "shipperCode"
                },
                {
                    title: "serviceCode",
                    key: "serviceCode"
                },
                {
                    title: "accountNumber",
                    key: "accountNumber",
                    render: (h, { row }) => {
                        return (
                            <a
                                onClick={this.handleOperates.bind(
                                    this,
                                    row.id,
                                    "query"
                                )}
                            >
                                {row.accountNumber}
                            </a>
                        );
                    }
                },
                {
                    title: "meterNumber",
                    key: "meterNumber"
                },
                {
                    title: "accountKey",
                    key: "accountKey"
                },
                {
                    title: "password",
                    key: "password"
                },
                {
                    title: "BillAcount",
                    key: "thirdPartyAccount"
                },
                {
                    title: "hubId",
                    key: "hubId"
                },
                {
                    title: "Creation time",
                    key: "createdAt"
                }
            ];
        }
    }
};
